<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/include.jsp"%>
<head>
	<script type="text/javascript" src='<s:url value="/scripts/CustomTreeUI.js" includeParams="none"/>'></script>
	<script type="text/javascript" src='<s:url value="/pages/querythemes/query/query.js" includeParams="none"/>'></script>
	<link rel="stylesheet" type="text/css" href='<s:url value="/scripts/column-tree.css" includeParams="none"/>'/>
	<script src='<s:url value="/dwr/interface/deployMeasureService.js" includeParams="none"/>' type="text/javascript"></script>
</head>
<body>
<div class="tleft"></div>
<div class="tright"></div>
<div class="tbg">发布主题名: <s:property value="qdDomain.name" /></div>

<s:form  id="measureForm" namespace="/querythemes" action="qdDomainDeploy!saveOrUpdateDeployMeasure.action">
<s:hidden name="strDomainId" id="qdDomain.id"/>
<s:hidden name="role.id" id="role_id"/>
<s:hidden name="searchQdDomain.name" id="searchQdDomain.name"/>
<s:hidden name="searchQdDomain.catalogId.catalogName" id="searchQdDomain.catalogId.catalogName"/>
<s:hidden name="searchQdDomain.catalogId.catalogId" id="searchQdDomain.catalogId.catalogId"/>
<s:hidden name="pageSize" id="pageSize"/>

<div id="ids" style="display:none"></div>
<table align="center"  cellpadding="1" cellspacing="1" class="tablelist">
	<s:if test="hasErrors()">
		<s:if test="hasFieldErrors()">
			<tr align="center">
				<td class="tableHeader2"><font color="red" size="4"><s:fielderror/></font></td>
				<td class="tableHeader2"></td>
			</tr>
		</s:if>
		<s:if test="hasActionErrors">
			<tr align="center">
				<td class="tableHeader2"><font color="blue"><s:actionerror/></font></td>
				<td class="tableHeader2"></td>
			</tr>
		</s:if>	
	</s:if>
	<tr class="listr2">
		<td align="right"><font color="red">*</font>角色名:</td>
		<td colspan="3" align="left" class="listr5">			
			<s:select cssClass="searchSelect"  id="strRole" list="roleList" name="strRoleId" listKey="id" listValue="detail" headerKey="" headerValue="--- Please Select ---" onChange="changeField()"></s:select>
		</td>		
	</tr>
	<tr class="listr2">
		<td colspan="4">
			<table align="center"  cellpadding="0" cellspacing="0" class="tablelist">
				<tr class="listr2">
					<td align="right">
						<table align="center"  cellpadding="0" cellspacing="0" class="tablelist">
							<tr class="listr2">
							   <td align="right" style="width:50%"></td>
							   <td align="left">待发布查询列字段列表:</td>								
							</tr>
						</table>						
					</td>
					<td align="center" rowspan="2">
							
							<input type="button" name="Submit2" value=">>" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="srcToDest('qdFieldIds','qdDeployFieldIds','checked')" />
							
							<br>
							<input type="button" name="Submit2" value=">>>>" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="srcToDest('qdFieldIds','qdDeployFieldIds','all')" />
							
							<br>
							<input type="button" name="Submit2" value="<<" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="srcToDest('qdDeployFieldIds','qdFieldIds','checked')" />
							
							<br>
							<input type="button" name="Submit2" value="<<<<" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="srcToDest('qdDeployFieldIds','qdFieldIds','all')"/>							
					</td>				
					<td align="left">
						已发布查询列字段列表:
					</td>
					<td align="left" rowspan="2">										
						<input type="button" name="Submit2" value="↑" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="toUpperOrDown('qdDeployFieldIds','step','up')" />										
						<br>
						<input type="button" name="Submit2" value="↑↑" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="toUpperOrDown('qdDeployFieldIds','top','up')" />
						<br>	
						<input type="button" name="Submit2" value="↓" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="toUpperOrDown('qdDeployFieldIds','step','down')" />
						<br>
						<input type="button" name="Submit2" value="↓↓" class="btn"  onmouseover="this.className='btn_hover'" onmouseout="this.className='btn'" onclick="toUpperOrDown('qdDeployFieldIds','bottom','down')" />
					</td>
				</tr>
				<tr class="listr2">
					<td align="right">
						<s:select id="qdFieldIds" name="qdFieldName" list="simplemeasuList"  listKey="id" listValue="name" size="15" multiple="true" style="width:50%">						    
					    </s:select>
						
					</td>
					<td align="left" style="width:20%">
						<s:select id="qdDeployFieldIds" name="qdDeployFieldName" list="deploySimplemeasuList"  listKey="id" listValue="name" size="15" multiple="true" style="width:100%">						    
						</s:select>
						<input type="hidden" id="mIds" name="measureIds" value="">
					</td>					
				</tr>
			</table>
		</td>
		
	</tr>	
</table>
<div class="tableHeader4"> 
	<input name="" type="button" value="保 存" class="add" onmouseover="this.className='add_hover'" onmouseout="this.className='add'"  onclick="save()"/>
	<input name="" type="button" value="返 回" class="back" onmouseover="this.className='back_hover'" onmouseout="this.className='back'" onclick="goback()" />	 
</div>
</s:form>


<script type="text/javascript">
	function srcToDest(srcid,destid,type){		
		var roleId = document.getElementById("strRole").value;
		if(roleId!=""){				 
		    var optionsObjects=document.getElementById(srcid);   
		    var optionsSubObjects=document.getElementById(destid);
		    if(type=="all"){
		    	//移动内容
		    	for(var o=0;o<optionsObjects.length;o++){
		    		var optionsvalue=optionsObjects.options[o].value;   
					var optionstext=optionsObjects.options[o].text;   
					addoptions(destid,optionstext,optionsvalue) 
		    	}
		    	
		    	//删除内容
		    	for(var o=optionsObjects.length-1;o>=0;o--){
		    		optionsObjects.options.remove(o);
		    	}
		    }else{
		    	//移动内容
		    	for(var o=0;o<optionsObjects.length;o++){
		    		if(optionsObjects.options[o].selected==true){   
					    var optionsvalue=optionsObjects.options[o].value;   
					    var optionstext=optionsObjects.options[o].text;   
					    addoptions(destid,optionstext,optionsvalue) 
					}		    		 
		    	}
		    	
		    	//删除内容
		    	for(var o=optionsObjects.length-1;o>=0;o--){
		    		if(optionsObjects.options[o].selected==true){ 
		    			optionsObjects.options.remove(o);
		    		}
		    	}
		    	
		    }
		}else{
			alert("请选择发布的角色！");
			return;
		}	      
	}
	
	function addoptions(objectid,textvalue,optionsvalue){   
		var optionsSubObjects=document.getElementById(objectid);   
		var hasexist=0;   
		for(var o=0;o<optionsSubObjects.length;o++){   
		 	var optionsvalue_sub=optionsSubObjects.options[o].text;   
		 	if(optionsvalue_sub==textvalue)   
		 		hasexist+=1;   
		}   
		if(hasexist==0){   
		 optionsSubObjects.add(new Option(textvalue, optionsvalue));   
		}   
	}   
	
	function removeoptions(objectid){
		var optionsObjects=document.getElementById(objectid);
		for(var o=optionsObjects.length-1;o>=0;o--){	    	
			optionsObjects.options.remove(o);	    	
	    }    	
	}
	    
    function changeField(){
    	var roleId = document.getElementById("strRole").value;
    	var strDomainId = document.getElementById("qdDomain.id").value;
    	
    	if(roleId!="" && strDomainId!=""){
    		deployMeasureService.getDeployMeasureList(strDomainId,roleId,setQdDeployFieldIds);
    		deployMeasureService.getMeasureList(strDomainId,roleId,setQdFieldIds);
    	}else{
    		removeoptions("qdDeployFieldIds");
			removeoptions("qdFieldIds");
    	}
    }
    
    function setQdDeployFieldIds(data){
    	removeoptions("qdDeployFieldIds");    	
    	if(data!="undefined" && data!=undefined){
    		for(var i=0;i<data.length;i++){    			    			
    			var optionsvalue=data[i].id;   
				var optionstext=data[i].name; 
				//alert("optionsvalue=="+optionsvalue+"   optionstext=="+optionstext);				
				addoptions("qdDeployFieldIds",optionstext,optionsvalue)   
    		}
    	}
    }
    
    function setQdFieldIds(data){
    	removeoptions("qdFieldIds");
    	if(data!="undefined" && data!=undefined){
    		for(var i=0;i<data.length;i++){    			    			
    			var optionsvalue=data[i].id;   
				var optionstext=data[i].name; 
				//alert("optionsvalue=="+optionsvalue+"   optionstext=="+optionstext);
				addoptions("qdFieldIds",optionstext,optionsvalue)   
    		}
    	}	   
    }
    
    function save(){ 
    	var roleId = document.getElementById("strRole").value;
    	if(roleId!=""){
	    	setMeasureIds("qdDeployFieldIds","mIds");
	    	document.all.measureForm.action="qdDomainDeploy!saveOrUpdateDeployMeasure.action";
	    	document.all.measureForm.submit();
    	}else{
    		alert("角色名不能为空，请选择!");
    		return;
    	}
    }
    
    
    function setMeasureIds(srcid,mIds){
    	var measureIds = "";
		var optionsObjects=document.getElementById(srcid);	       
		//for(var o=optionsObjects.length-1;o>=0;o--){
		for(var o=0;o<optionsObjects.length;o++){
		 	var optionsvalue=optionsObjects.options[o].value;   
			measureIds+=optionsvalue+";";		    	
		}
		document.getElementById(mIds).value = measureIds;		    		      
	}
	
    
    function goback(){
    	window.parent.document.all.frameForm.action="qdDomainDeploy!load4FindDomain.action";
    	window.parent.document.all.frameForm.submit();    	
    }
</script>
</body>